<template>
  <div class="edit-case">
	  <core v-if="visible" :patient-id="patientId" :ill-type="illType" :id="id" pattern="view" :value="caseDetail" @update-value="reLoad"></core>
  </div>
</template>

<script>
import { getCaseDetail } from "../../utils/actions";
import core from "./core";
export default {
	name: "case-edit",
	props: {
		id: {
			type: [String, Number],
			required: false
		}
	},
	components: {
		core
	},
	data() {
		return {
			illType: "",
			caseDetail: [],
			patientId: null,
			visible: false
		};
	},
	methods: {
		openLoading() {
			const loading = this.$loading({
				lock: true,
				text: "Loading",
				spinner: "el-icon-loading",
				background: "rgba(0, 0, 0, 0.7)"
			});
			return loading;
		},
		reLoad() {
			this.load(true);
		},
		load(reload = false) {
			let loading = this.openLoading();
			getCaseDetail(this.id)
				.then(res => {
					res = JSON.parse(res);
					if (reload) {
						this.caseDetail = [];
					}
					for (let i in res.forms) {
						this.caseDetail.push(res.forms[i]);
					}
					this.illType = res.templateName;
					this.patientId = res.patientId;
					this.visible = true;
					loading.close();
				})
				.catch(err => {
					loading.close();
					this.$message.error("获取详情失败," + err.message);
				});
		}
	},
	created() {
		this.load();
	}
};
</script>

<style>

</style>
